home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / WASTE / Extras / Unsupported / WEExtraHooks.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.1 KB  |  152 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    WEExtraHooks.c
  3.  *
  4.  *    Hooks for adding no-wrap behavior and "show invisibles" to WASTE
  5.  *    Written by Jonathan Kew
  6.  *
  7.  */
  8.  
  9. #include "WEExtraHooks.h"
  10.  
  11. static const Point kOneToOneScaling = { 1, 1 } ;
  12.  
  13. pascal StyledLineBreakCode _WENoWrapLineBreak
  14.     (
  15.         Ptr pText ,
  16.         SInt32 textLength ,
  17.         SInt32 textStart ,
  18.         SInt32 textEnd ,
  19.         Fixed * textWidth ,
  20.         SInt32 * textOffset ,
  21.         WEReference we
  22.     )
  23. {
  24. #pragma unused ( textLength, textWidth, we )
  25.  
  26.     SInt32 ii ;
  27.     StyledLineBreakCode breakCode = smBreakOverflow ;
  28.  
  29.     for ( ii = textStart ; ii < textEnd ; ii ++ )
  30.     {
  31.         if ( pText [ ii ] == kEOL )
  32.         {
  33.             breakCode = smBreakWord ;
  34.             *textOffset = ii + 1 ;
  35.             break ;
  36.         }
  37.     }
  38.  
  39.     if ( breakCode == smBreakOverflow )
  40.     {
  41.         * textOffset = ii ;
  42.     }
  43.  
  44.     return breakCode ;
  45. }
  46.  
  47. // This "show invisibles" hook is *not* ready for prime time -- it's inefficient and not
  48. // compatible with other features such as RL text. This is just an experiment!
  49. pascal void _WEShowInvisiblesDrawText
  50.     (
  51.         Ptr pText ,
  52.         SInt32 textLength ,
  53.         Fixed slop ,
  54.         JustStyleCode styleRunPosition ,
  55.         WEReference we
  56.     )
  57. {
  58.     //    these are "static" to avoid the overhead of setting them up on the fly
  59.     //    (note that the both the baseAddr field and the rowBytes field of a BitMap
  60.     //    *must* be even!)
  61.     static long tabIcon [ ] = { 0x00000800, 0x0c007e00, 0x7f007e00, 0x0c000800} ;
  62.     static BitMap tabBitMap = { (Ptr) tabIcon, 2, { 0, 0, 8, 8 } } ;
  63.     static long parIcon [ ] = { 0x3f006500, 0x65006500, 0x3d000500, 0x05000500} ;
  64.     static BitMap parBitMap = { (Ptr) parIcon, 2, { 0, 0, 8, 8 } } ;
  65.  
  66.     WEDrawTextUPP oldDrawTextProc = nil ;
  67.     WECharToPixelUPP charToPixelProc = nil ;
  68.     GrafPtr port ;
  69.     Rect dstRect ;
  70.     Point startPt ;
  71.     SInt32 i, width, halfSpaceWidth = 0x80000000 ;
  72.     RGBColor color ;
  73.  
  74.     GetPort ( & port ) ;
  75.     GetPen ( & startPt ) ;
  76.  
  77.     //    first draw the text using the original draw hook,
  78.     //    which was saved by WEInstallShowInvisiblesHook
  79.     if ( WEGetUserInfo ( kInvisiblesOldDrawTextProcTag, ( SInt32 * ) & oldDrawTextProc, we ) == noErr )
  80.     {
  81.         CallWEDrawTextProc ( pText, textLength, slop, styleRunPosition, we, oldDrawTextProc ) ;
  82.     }
  83.  
  84.     if ( IsColorPort ( port ) )
  85.     {
  86.         SInt32 temp ;
  87.  
  88.         //    default invisibles color is light gray
  89.         color . red = 0xAAAA ;
  90.         color . green = 0xAAAA ;
  91.         color . blue = 0xAAAA ;
  92.  
  93.         if ( WEGetUserInfo ( kInvisiblesColorRedGreenTag , & temp, we ) == noErr )
  94.         {
  95.             * ( SInt32 * ) & color = temp ;
  96.             if ( WEGetUserInfo ( kInvisiblesColorBlueTag, & temp, we ) == noErr )
  97.             {
  98.                 color . blue = temp ;
  99.             }
  100.         }
  101.         RGBForeColor ( & color ) ;
  102.     }
  103.  
  104.     //    retrieve CharToPixel hook
  105.     if ( WEGetInfo ( weCharToPixelHook, & charToPixelProc, we ) != noErr )
  106.     {
  107.         return ;
  108.     }
  109.  
  110.     for ( i = 0 ; i < textLength ; ++ i )
  111.     {
  112.         if ( pText [ i ] == ' ' )
  113.         {
  114.             width = CallWECharToPixelProc ( pText, textLength, slop, i, leftCaret,
  115.                 styleRunPosition, startPt . h, we, charToPixelProc ) ;
  116.             if ( halfSpaceWidth == 0x80000000 )
  117.             {
  118.                 halfSpaceWidth = CallWECharToPixelProc ( pText, textLength, slop, i + 1, leftCaret,
  119.                     styleRunPosition, startPt . h, we, charToPixelProc ) ;
  120.                 halfSpaceWidth = ( halfSpaceWidth - width ) >> 1 ;
  121.             }
  122.             dstRect . left = startPt . h + width + halfSpaceWidth ;
  123.             dstRect . right = dstRect . left + 1 ;
  124.             dstRect . top = startPt . v - 3 ;
  125.             dstRect . bottom = startPt . v - 2 ;
  126.             PaintRect ( & dstRect ) ;
  127.         }
  128.         else if ( pText [ i ] == '\t' )
  129.         {
  130.             width = CallWECharToPixelProc ( pText, textLength, slop, i, leftCaret,
  131.                 styleRunPosition, startPt . h, we, charToPixelProc ) ;
  132.             dstRect . left = startPt . h + width ;
  133.             dstRect . right = dstRect . left + 8 ;
  134.             dstRect . top = startPt . v - 8 ;
  135.             dstRect . bottom = startPt . v ;
  136.             CopyBits ( & tabBitMap, & port -> portBits, & tabBitMap . bounds, & dstRect, srcCopy, nil ) ;
  137.         }
  138.     }
  139.  
  140.     if ( ( textLength > 0 ) &&
  141.          ( pText + textLength <= * WEGetText ( we ) + WEGetTextLength ( we ) ) &&
  142.          ( pText [ textLength - 1 ] == kEOL ) )
  143.     {
  144.         GetPen ( & startPt ) ;        // that's really the endpoint now!
  145.         dstRect . left = startPt.h ;
  146.         dstRect . right = dstRect.left + 8 ;
  147.         dstRect . top = startPt.v - 8 ;
  148.         dstRect . bottom = startPt.v ;
  149.         CopyBits ( & parBitMap, & port -> portBits, & parBitMap . bounds, & dstRect, srcCopy, nil ) ;
  150.     }
  151. }
  152.